<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/12/10
 * Time: 18:51
 */
namespace app\common\helper;

use app\common\model\KeyStat;

class key_stat_helper
{
    /**
     * 新增关键词
     * @param unknown_type $key_id
     * @param unknown_type $info
     */
    public static function update_key_stat($key_id, $info, $company_id = 0, $open_card_id = 0)
    {
        if (!$open_card_id) {
            $open_card_id = open_card_helper::get_open_card_id();
        }
        if (!$company_id) {
            $company_id = company_helper::get_company_id();
        }

        $filter = $update_info = array('company_id'=>$company_id, 'open_card_id'=>$open_card_id, 'key_id'=>$key_id);
        // 过滤数据
        foreach ($info as $k=>$v) {
            $update_info[$k] = filter_string($v);
        }

        $key_stat_info = _uri('key_stat', $filter);
        if ($key_stat_info) {
            $update_info['num'] = $key_stat_info['num']+1;

            KeyStat::update($update_info, $filter);
        } else {
            $update_info['num'] = 1;
            KeyStat::create($update_info);
        }

        return true;
    }
}